{% extends "base.html" %}

{% block content %}

    <!--{% if messages %}
    <ul class="messages">
        {% for message in messages %}
        <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
        {% endfor %}
    </ul>
    {% endif %}-->

    {% if search_request %}
    <div class="page-header">
        <h2>Výsledky hľadania</h2>
        Pre výraz <span class="label">{{ search_request }}</span>
        {% if result_list %} bolo nájdených <span class="label">{{ result_list|length }}</span> výsledkov. {% else %} neboli nájdené žiadne výsledky. {% endif %}
    </div>
    
    {% if result_list %}
    
    <script type="text/javascript">
	$(document).ready(function(){ 
	    $("#achi_resultlist").tablesorter(); 
	}); 
    </script>
				    
    <table id="achi_resultlist" class='table tablesorter table-striped table-bordered'>
	<thead>
	    <tr>
		<th>Názov</th>
		<th>Bodovanie</th>
		<th>Autor</th>
		<th>Vytvorenie</th>
		<th>Atribúty</th>
	    </tr>
	</thead>
        <tbody>
        {% for res in result_list %}
        <tr>
        <td>
        <a href="{% url show_one_achievement achievement_id=res.uuid %}">{{res.name}}</a>
        </td>
        
        <td>
        {% if res.points == 0 %}
            <span class="label">Bez odmeny</span>
        {% else %}
            {% if res.points == 1 %}
                <span class="badge badge-info">{{ res.points }}</span> bod
            {% else %}
                <span class="badge badge-info">{{ res.points }}</span> bodov
            {% endif %}
        {% endif %}
        </td>
        
        <td>
            {% if not res.author %}
                <span class="label label-info">Spoločný</span>
            {% else %}
                <span class="label label-inverse"><a href="{% url show_user user_id=res.author.username %}">{{res.author}}</a></span>
            {% endif %}
        </td>
        
        
        {% if res.parse_attributes|safe %}
            <td>
                {{ res.pub_date }}
            </td>
            <td>
                {{ res.parse_attributes|safe }}
            </td>
        {% else %}
            <td colspan="2">
                {{ res.pub_date }}
            </td>
        {% endif %}
        </tr>
        {% endfor %}
        </tbody>
    </table>
    {% endif %}
    
    {% endif %}
    
    
    {% if not search_request or search_request and not result_list %}

    <div class="page-header">
        <h2>Zoznam achievementov
        <!--
        <form class="navbar-search pull-right">
            <input type="text" class="search-query" placeholder="Hľadať...">
        </form>
        -->
        </h2>
        
    </div>

    {% if achievement_list %}
    
    <div class="row-fluid">
    
    <div class="tabbable">
        <div class="span2">
            <ul class="nav nav-list">
                <li class="nav-header">Kategória</li>
                
                {% if category_list %}
                
                    {% for cat in category_list.keys %}
                        <li><a href="#cat{{cat.id}}" data-toggle="tab">{{cat.name}}</a></li>
                    {% endfor %}
                
                {% endif %}
                
                <li class="nav-header">Iné</li>
                
                {% if category_list %}
                    <li><a href="#nocategory" data-toggle="tab">Bez kategórie</a></li>
                {% endif %}
                
                <li class="active"><a href="#all" data-toggle="tab" style="color:lightblue;">Všetky</a></li>
            </ul>
        </div>
        <div class="tab-content">
        
            {% if category_list %}
                    
                {% for cat, achis in category_list.iteritems %}
                    <div class="tab-pane" id="cat{{cat.id}}">
                        <div class="span10" style="margin-left:20px;">
                            <h3>{{cat.name}}</h3>
                            <h5>{{cat.description}}</h5>
                            <br>
                        
                            {% if achis %}
                            
                            <script type="text/javascript">
				$(document).ready(function(){ 
				    $("#cat{{cat.id}}_achi_table").tablesorter(); 
				}); 
			    </script>
							    
			    <table id="cat{{cat.id}}_achi_table" class='table tablesorter table-striped table-bordered'>
				<thead>
				    <tr>
					<th>Názov</th>
					<th>Bodovanie</th>
					<th>Autor</th>
					<th>Vytvorenie</th>
					<th>Atribúty</th>
				    </tr>
				</thead>
                                <tbody>
                                    {% for achi in achis %}
                                        <tr>
                                            <td><a href="{% url show_one_achievement achievement_id=achi.0.uuid %}">{{achi.0.name}}</a>
                                            {% if achi.1 %}
                                                <span class="label label-success" style="margin-left:10px;">Splnený</span>
                                            {% endif %}
                                            </td>
                                            
                                            <td>
                                            {% if achi.0.points == 0 %}
                                                <span class="label">Bez odmeny</span>
                                            {% else %}
                                                {% if achi.0.points == 1 %}
                                                    <span class="badge badge-info">{{ achi.0.points }}</span> bod
                                                {% else %}
                                                    <span class="badge badge-info">{{ achi.0.points }}</span> bodov
                                                {% endif %}
                                            {% endif %}
                                            </td>
                                            
                                            <td>
                                                {% if not achi.0.author %}
                                                    <span class="label label-info">Spoločný</span>
                                                {% else %}
                                                    <span class="label label-inverse"><a href="{% url show_user user_id=achi.0.author.username %}">{{achi.0.author}}</a></span>
                                                {% endif %}
                                            </td>
                                            
                                            
                                            {% if achi.0.parse_attributes|safe %}
                                                <td>
                                                    {{ achi.0.pub_date }}
                                                </td>
                                                <td>
                                                    {{ achi.0.parse_attributes|safe }}
                                                </td>
                                            {% else %}
                                                <td colspan="2">
                                                    {{ achi.0.pub_date }}
                                                </td>
                                            {% endif %}
                                            
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                            {% else %}
                                <div class="well well-small">V tejto kategórii nie sú žiadne achievementy.</div>
                            {% endif %}
                        </div>
                    </div>
                {% endfor %}
                        
            <div class="tab-pane" id="nocategory">
                <div class="span10" style="margin-left:20px;">
                    <h3>Bez kategórie</h3>
                
                    <script type="text/javascript">
			$(document).ready(function(){ 
			    $("#nocat_achi_table").tablesorter(); 
			}); 
		    </script>
						    
		    <table id="nocat_achi_table" class='table tablesorter table-striped table-bordered'>
			<thead>
			    <tr>
				<th>Názov</th>
				<th>Bodovanie</th>
				<th>Autor</th>
				<th>Vytvorenie</th>
				<th>Atribúty</th>
			    </tr>
			</thead>
                        <tbody>
                        {% for achi, cmp in achievement_list.iteritems %}
                            {% if not achi.category %}
                        
                            <tr>
                                <td><a href="{% url show_one_achievement achievement_id=achi.uuid %}">{{ achi.name }}</a>
                                {% if cmp %}
                                    <span class="label label-success" style="margin-left:10px;">Splnený</span>
                                {% endif %}
                                </td>
                                <td>
                                {% if achi.points == 0 %}
                                    <span class="label">Bez odmeny</span>
                                {% else %}
                                    {% if achi.points == 1 %}
                                        <span class="badge badge-info">{{ achi.points }}</span> bod
                                    {% else %}
                                        <span class="badge badge-info">{{ achi.points }}</span> bodov
                                    {% endif %}
                                {% endif %}
                                </td>
                                <td>
                                    {% if not achi.author %}
                                        <span class="label label-info">Spoločný</span>
                                    {% else %}
                                        <span class="label label-inverse"><a href="{% url show_user user_id=achi.author %}">{{achi.author}}</a></span>
                                    {% endif %}
                                </td>
                                
                                {% if achi.parse_attributes|safe %}
                                <td>
                                    {{ achi.pub_date }}
                                </td>
                                <td>
                                    {{ achi.parse_attributes|safe }}
                                </td>
                                {% else %}
                                <td colspan="2">
                                    {{ achi.pub_date }}
                                </td>
                                {% endif %}
                                
                            </tr>
                            
                                {% endif %}
                        {% endfor %}
                        <tbody>
                    </table>
                </div>
            </div>
            
            {% endif %}
            
            <div class="tab-pane active" id="all">
                <div class="span10" style="margin-left:20px;">
                    <h3>Všetky</h3>
                    <script type="text/javascript">
			$(document).ready(function(){ 
			    $("#all_achi_table").tablesorter(); 
			}); 
		    </script>
						    
		    <table id="all_achi_table" class='table tablesorter table-striped table-bordered'>
			<thead>
			    <tr>
				<th>Názov</th>
				<th>Bodovanie</th>
				<th>Autor</th>
				<th>Vytvorenie</th>
				<th>Atribúty</th>
			    </tr>
			</thead>
                        <tbody>
                        {% for achi, cmp in achievement_list.iteritems %}
                            <tr>
                                <td><a href="{% url show_one_achievement achievement_id=achi.uuid %}">{{ achi.name }}</a>
                                {% if cmp %}
                                    <span class="label label-success" style="margin-left:10px;"><i class="icon-white icon-ok"></i></span>
                                {% endif %}
                                </td>
                                <td>
                                {% if achi.points == 0 %}
                                    <span class="label">Bez odmeny</span>
                                {% else %}
                                    <span class="badge badge-info">{{ achi.points }}</span>
                                    {% if achi.points == 1 %}bod
				     {% else %}
					  {% if achi.points >= 2 and achi.points <= 4 %}body
					  {% else %}bodov
					  {% endif %}
				     {% endif %}
                                {% endif %}
                                </td>
                                
                                <td>
                                    {% if not achi.author %}
                                        <span class="label label-info">Spoločný</span>
                                    {% else %}
                                        <span class="label label-inverse"><a href="{% url show_user user_id=achi.author %}">{{achi.author}}</a></span>
                                    {% endif %}
                                </td>
                                
                                {% if achi.parse_attributes|safe %}
                                <td>
                                    {{ achi.pub_date }}
                                </td>
                                <td>
                                    {{ achi.parse_attributes|safe }}
                                </td>
                                {% else %}
                                <td colspan="2">
                                    {{ achi.pub_date }}
                                </td>
                                {% endif %}
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    
    </div>
    
    
    {% else %}
        <p> Nie sú dostupné žiadne spoločné achievementy. </p>
    {% endif %}
    
    
    {% endif %}

{% endblock %}

